package com.slavshik.utils {
	import assets.TfMc;

	import flash.text.AntiAliasType;
	import flash.text.GridFitType;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	/**
	 * @author Alexander Slavshik
	 */
	public class Fonts {
		
//		[Embed(source='../../../../libs/arial.ttf', fontName='Arial', mimeType='application/x-font', unicodeRange='U+0400-U+04FF,U+0000-U+007F')]
//		protected static var defaultFontCls : Class;
//		private var _defaultFont : Font;
		
		private static const FONT_NAME:String = "Arial";
		
		private static var _instance:Fonts;
		
		public static function getInstance():Fonts {
			if (!_instance) {
				_instance = new Fonts();
			}
			return _instance;
		}
		
		public function Fonts() {
			init();
		}

		protected function init() : void {
			new TfMc();
//			_defaultFont = new defaultFontCls() as Font;
		}

		public function applyTfTextFormat(tf:TextField, bold:Boolean = true):TextField {
			if(tf) {
				tf.antiAliasType = AntiAliasType.ADVANCED;
				tf.gridFitType = GridFitType.SUBPIXEL;
				var fmt : TextFormat = new TextFormat(FONT_NAME);
				fmt.bold = bold;
				tf.defaultTextFormat = fmt;
				tf.mouseEnabled = false;
				tf.embedFonts = true;
				tf.text = tf.text;
				//tf.filters = [_defaultFilter];
			}
			
			return tf;
		}
		
//		public function applyTiTextFormat(ti:TextInput, format:TextFormat, disabledFormat:TextFormat = null):TextInput {
//			//format.font = FONT_NAME;
//			ti.setStyle("textFormat" , format);
//			ti.setStyle("embedFonts", true);
//			if (disabledFormat) {
//				//disabledFormat.font = FONT_NAME;
//				ti.setStyle("disabledTextFormat", disabledFormat);
//			} else {
//				ti.setStyle("disabledTextFormat", format);
//			}
//			return ti;
//		}
//		
//		public function applyTaTextFormat(ti:TextArea, format:TextFormat, disabledFormat:TextFormat = null):TextArea {
//			//format.font = FONT_NAME;
//			ti.setStyle("textFormat" , format);
//			ti.setStyle("embedFonts", true);
//			if (disabledFormat) {
//				//disabledFormat.font = FONT_NAME;
//				ti.setStyle("disabledTextFormat", disabledFormat);
//			} else {
//				ti.setStyle("disabledTextFormat", format);
//			}
//			return ti;
//		}
		
		public function getDefaultTf(text:String = ''):TextField {
			var tf:TextField = new TextField();
			tf.width = 100;
			tf.height = 10;
			tf.multiline = true;
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.wordWrap = true;
			tf.text = text;
			
			return tf;
		}
		
		public function applyHtmlTextFormat(tf:TextField, styleSheet:StyleSheet):TextField {
			//css.setStyle('.price', {fontFamily:_defaultFont.fontName, fontSize:22, color:'#000000', display:"inline"});
			//css.setStyle('.priceNum', {color:'#a64f1b', fontSize:25});
			tf.styleSheet = styleSheet;
			tf.antiAliasType = AntiAliasType.ADVANCED;
			tf.gridFitType = GridFitType.SUBPIXEL;
			tf.embedFonts = true;
			tf.mouseEnabled = false;
			return tf;
		}
		/*
		public static function applyContractsFont(txt:TextField):TextField {
			var css:StyleSheet = new StyleSheet();
			css.setStyle('.total', {color:'#C75224', fontFamily:_fontName, fontWeight:'bold'});
			css.setStyle('.current', {color:'#8F5017', fontFamily:_fontName, fontWeight:'bold'});
			txt.styleSheet = css;
			if(_embedFonts){
				txt.mouseEnabled = false;
				txt.antiAliasType = AntiAliasType.ADVANCED;
				txt.gridFitType = GridFitType.SUBPIXEL;
				txt.embedFonts = true;
			}
			return txt;
		}
		*/
	}
}
